﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STDTO.DataTransferObjects.Interfaces;

namespace STDTO.DataTransferObjects.Impl
{
    /// <summary>
    /// Save the mapping between Concrete object and is Dto matching object
    /// </summary>
    internal class DataTrasferObjectToEntityMapper : IDataTrasferObjectToEntityMapper
    {
        private Dictionary<object, object> m_dtoToEntityDic = new Dictionary<object, object>();
        private Dictionary<object, object> m_EntityToDtoDic = new Dictionary<object, object>();

        public void AddMapping(object dtoObject, object entity)
        {
            m_dtoToEntityDic.Add(dtoObject, entity);
            m_EntityToDtoDic.Add(entity, dtoObject);
        }

        public bool TryGetDataTransferObject(object entity, out object dtoObject)
        {
            dtoObject = null;

            if (m_EntityToDtoDic.ContainsKey(entity))
            {
                dtoObject = m_EntityToDtoDic[entity];
                return true;
            }
            return false;
        }


        public bool TryGetEntity(object dtoObject, out object entity)
        {
            entity = null;

            if (m_dtoToEntityDic.ContainsKey(dtoObject))
            {
                entity = m_dtoToEntityDic[dtoObject];
                return true;
            }
            return false;
        }
    }
}
